import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Transparency;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;


public class GameUtils
{
	
	private static BufferedImage createClipImage(Graphics2D g, Shape s) {
	    // Create a translucent intermediate image in which we can perform
	    // the soft clipping
		Rectangle2D rect = s.getBounds2D();
		int width = (int) rect.getWidth();
		int height = (int) rect.getHeight();
	    GraphicsConfiguration gc = g.getDeviceConfiguration();
	    BufferedImage img = gc.createCompatibleImage(width,height, Transparency.TRANSLUCENT);
	    Graphics2D g2 = img.createGraphics();

	    // Clear the image so all pixels have zero alpha
	    g2.setComposite(AlphaComposite.Clear);
	    g2.fillRect(0, 0, width, height);

	    // Render our clip shape into the image.  Note that we enable
	    // antialiasing to achieve the soft clipping effect.  Try
	    // commenting out the line that enables antialiasing, and
	    // you will see that you end up with the usual hard clipping.
	    g2.setComposite(AlphaComposite.Src);
	    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	    g2.setColor(Color.WHITE);
	    g2.fill(s);
	    g2.dispose();

	    return img;
	}
	
	/*
	 * From http://weblogs.java.net/blog/campbell/archive/2006/07/java_2d_tricker_2.html
	 */
//	Shape clipShape = createClipShape();
//	//Shape clipShape = new Ellipse2D.Float(width/4, height/4, width/2, height/2);
//
//	// Clear the background to white
//	g.setColor(Color.WHITE);
//	g.fillRect(0, 0, width, height);
//
//	// Set the clip shape
//	BufferedImage clipImage = createClipImage(clipShape);
//	Graphics2D g2 = clipImage.createGraphics();
//
//	// Fill the shape with a gradient
//	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//	g2.setComposite(AlphaComposite.SrcAtop);
//	g2.setPaint(new GradientPaint(0, 0, clrHi, 0, height, clrLo));
//	g2.fill(clipShape);
//
//	// Apply the border glow effect
//	paintBorderGlow(g2, 8);
//
//	g2.dispose();
//
//	g.drawImage(clipImage, 0, 0, null);

	
}
